//================v1要点总结===============
/**
 * 全排列
 */

/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var permute = function (nums) {
    let n = nums.length
    let flag = new Array(n).fill(false)
    let tempArr = new Array(n).fill(0)
    let rslt = []

    function dfs(index, len) {
        if (len === n) {
            rslt.push([...tempArr])
            return
        }
        for (let i = 0; i < n; i++) {
            if (!flag[i]) {
                flag[i] = true
                tempArr[index] = nums[i]
                dfs(index + 1, len + 1)
                flag[i] = false
            }
        }
    }
    dfs(0, 0)
    return rslt
};


console.log(permute([1, 2, 3]))